package net.entelijan.cobean.examples.showcase.bind.table;

import java.awt.Color;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;

import net.entelijan.cobean.examples.util.ExamplesUtil;
import net.entelijan.scf.DefaultShowcasePanel;
import net.miginfocom.swing.MigLayout;

public class MasterDetailTablePanel extends DefaultShowcasePanel {

	private JTextField titleTextField = new JTextField();
	private JTextField yearTextField = new JTextField();
	private JTextField authorTextField = new JTextField();

	private JTextField failureTextField = createFailureTextField();

	private JTextField filterText = new JTextField();

	private JTable table = new JTable();

	private JButton showSelectionButton = new JButton("Show Selected Book");

	private JButton selectFirstBookButton = new JButton("Select First Book");

	private static final long serialVersionUID = 1L;

	public MasterDetailTablePanel() {
		super();
		setLayout(new MigLayout());
		add(this.filterText, "span 2, w max, wrap");
		add(new JScrollPane(this.table), "span 2, w max, h max, wrap");
		add(new JLabel(""), "w 100:100:max");
		add(this.failureTextField, "span 2, wrap, w max");
		add(createJLabel("Title"), "grow");
		add(this.titleTextField, "w max, wrap");
		add(createJLabel("Year"), "grow");
		add(this.yearTextField, "w max, wrap");
		add(createJLabel("Author"), "grow");
		add(this.authorTextField, "w max, wrap");
		add(new JPanel(), "w max, span 2, h 10:10:10, wrap");

		add(ExamplesUtil.createButtonsPanel(130, this.showSelectionButton,
				this.selectFirstBookButton), "span 2");
	}

	private JLabel createJLabel(String text) {
		JLabel re = new JLabel(text);
		re.setHorizontalAlignment(JLabel.RIGHT);
		return re;
	}

	private JTextField createFailureTextField() {
		JTextField re = new JTextField();
		re.setBorder(null);
		re.setForeground(Color.RED);
		re.setEditable(false);
		re.setFocusable(false);
		return re;
	}

	public JTable getTable() {
		return table;
	}

	public void setTable(JTable table) {
		this.table = table;
	}

	public JButton getShowSelectionButton() {
		return showSelectionButton;
	}

	public void setShowSelectionButton(JButton showSelectionButton) {
		this.showSelectionButton = showSelectionButton;
	}

	public JTextField getFilterText() {
		return filterText;
	}

	public void setFilterText(JTextField filterText) {
		this.filterText = filterText;
	}

	public JTextField getTitleTextField() {
		return titleTextField;
	}

	public void setTitleTextField(JTextField titleTextField) {
		this.titleTextField = titleTextField;
	}

	public JTextField getYearTextField() {
		return yearTextField;
	}

	public void setYearTextField(JTextField yearTextField) {
		this.yearTextField = yearTextField;
	}

	public JTextField getAuthorTextField() {
		return authorTextField;
	}

	public void setAuthorTextField(JTextField authorTextField) {
		this.authorTextField = authorTextField;
	}

	public JTextField getFailureTextField() {
		return failureTextField;
	}

	public void setFailureTextField(JTextField failureTextField) {
		this.failureTextField = failureTextField;
	}

	public JButton getSelectFirstBookButton() {
		return selectFirstBookButton;
	}

	public void setSelectFirstBookButton(JButton selectFirstBookButton) {
		this.selectFirstBookButton = selectFirstBookButton;
	}

}
